Skip to content

fix: assertFails for storage read/write requests (#5086) #5209

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

lovelle-cardoso
Copy link
Contributor

@lovelle-cardoso lovelle-cardoso commented Jul 28, 2021

Fixes Issue 4 of #5086

Discussion

#5086

This PR makes assertFails work properly with the storage emulator.

Most storage permission errors throw errors with the message "(storage/unauthorized)", but assertFails only checks for the string "permission denied". This means that assertFails won't work properly for most storage unit tests.

This fix is a small one that just adds another check if the message contains the string "unauthorized". A better fix would be to ensure that all firebase products throw consistent error message codes when permission is denied, but this solution will at least fix this bug in the unit testing library for storage for the time being.

Testing

  • Added unit test to packages/rules-unit-testing/test/database.test.ts called 'assertFails() if message contains unauthorized'

NOTE: It would be better if the rules-unit-testing library also contained tests for real-world usage (like actually spinning up the emulators and checking assertFails and assertSucceeds for basic actions like reading/writing from firestore, realtiime database, or storage). I think having just a few basic tests for usage would have caught this issue much quicker.

@changeset-bot
Copy link

changeset-bot bot commented Jul 28, 2021

⚠️ No Changeset found

Latest commit: c206068

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Contributor

@avolkovi avolkovi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks for the fix and detailed test!

@yuchenshi yuchenshi merged commit c52eb48 into firebase:master Aug 3, 2021
@firebase firebase locked and limited conversation to collaborators Sep 3, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants